import { ResPage, Result, ResultData } from "@/api/interface/index";
import { Organization, User } from "@/api/interface/userManagement";
import { BASE } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 用户管理模块
 */
// 获取用户列表
export const getUserList = (params: { page: number; page_size: number }) => {
  return http.get<ResPage<User.ResUserList>>(BASE + `/user/`, params); // 正常 post json 请求  ==>  application/json
};

// 同步用户
export const userSync = () => {
  return http.post(BASE + `/user/sync/`);
};

// 获取组织机构树
export const getTreeList = () => {
  return http.get<ResPage<Organization.ResOrganizationList>>(BASE + `/organization/`);
};

// 创建组织机构树
export const treeCreate = params => {
  return http.post(BASE + `/organization/`, params);
};

// 更新组织机构树
export const treeModify = (id, params) => {
  return http.put(BASE + `/organization/${id}/`, params);
};

// 删除组织机构树
export const treeDelete = (id: number) => {
  return http.delete<ResultData>(BASE + `/organization/${id}/`);
};

// 删除用户
export const userTerminate = params => {
  console.log(params);
  return http.delete<Result>(BASE + `/user/delete/`, { params: params });
};

// 禁用用户
export const userDisable = (params: { ids: any[] }) => {
  return http.post(BASE + `/user/disable/`, params);
};

// 启用用户
export const userEnable = (params: { ids: any[] }) => {
  return http.post(BASE + `/user/enable/`, params);
};

// 编辑用户
export const userModify = (id, params) => {
  return http.put(BASE + `/user/${id}/`, params);
};

// 创建用户
export const userCreate = params => {
  return http.post(BASE + `/user/`, params);
};

// 获取用户详情
export const getUserDetail = id => {
  return http.get<User.ResUserList>(BASE + `/user/${id}/`);
};

// 获取用户个人信息
export const getUserInfo = () => {
  return http.get<User.ResUserList>(BASE + `/user/info/`);
};
